<template>
  <div class="AttractInvestment">
    <!--banner-->
    <!-- <div class="banner">
      <div class="wh-1200 auto banner-txt pt-50">
        <h1>金融信贷</h1>
        <span>Finance Credit</span>
      </div>
    </div> -->
    <!-- autoplay -->
    <div class="banner-box wh-1200 auto">
      <div class="arrow prev" @click="() => $refs.carouseRef.prev()">
        <a-icon type="left-circle" />
      </div>
      <div class="arrow next" @click="() => $refs.carouseRef.next()">
        <a-icon type="right-circle" />
      </div>
      <a-carousel autoplay ref="carouseRef">
        <div
          class="banner-item"
          v-for="item in bannerList"
          :key="item.id"
          :style="{
            backgroundImage: `url(${item.poster})`,
            backgroundRepeat: 'no-repeat',
            backgroundSize: '100% 100%',
          }"
          @click="toDetail(item.prodId)"
        >
          <h3 class="banner-txt">{{ item.name }}</h3>
        </div>
      </a-carousel>
    </div>
    <!-- <Suggest /> -->
    <div v-if="getToken()" class="wh-1200 auto main mt-40 mb-40">
      <div class="main-title mt-40">
        <img src="@/assets/images/tips.png" alt />
        <span>为您推荐</span>
      </div>
      <Suggest
        :prodcutTypes="prodcutTypes"
        :loanTypes="loanTypes"
        @selected="toDetail"
      />
    </div>

    <!--金融信贷-->
    <div class="wh-1200 auto main mt-40">
      <!-- 标题模块 -->
      <div class="main-title mt-40">
        <img src="@/assets/images/tips.png" alt />
        <span>信贷金融</span>
      </div>

      <!-- 搜索模块 -->
      <div class="main-search">
        <a-form-model :label-col="{ span: 2 }">
          <a-form-model-item label="关键字">
            <a-input v-model="form.keyword" placeholder="请输入信贷产品名称" />
            <a-button class="ant-btn1" @click="SearchData">搜索</a-button>
            <span @click="show = !show" v-show="!show" class="show-btn">
              高级搜索
              <a-icon type="caret-right" />
            </span>
            <span
              @click="show = !show"
              v-show="show"
              class="show-btn"
              style="color: #188af1"
            >
              高级搜索
              <a-icon type="caret-down" />
            </span>
          </a-form-model-item>
        </a-form-model>

        <div v-show="show">
          <div>
            <a-form-model
              ref="ruleForm"
              :model="form"
              class="mt-10"
              :label-col="{ span: 2 }"
              :wrapper-col="{ span: 14 }"
            >
              <!-- <a-form-model-item label="行业类别：" prop="region">
                <a-select v-model="form.region" placeholder="请选择" style="width: 120px" class="mr-32">
                  <a-select-option v-for="(item, index) in selectType" :key="index" :value="item.name">{{ item.name }}</a-select-option>
                </a-select>
                <a-select v-model="form.region" placeholder="请选择" style="width: 120px" class="mr-32">
                  <a-select-option v-for="(item, index) in selectType" :key="index" :value="item.name">{{ item.name }}</a-select-option>
                </a-select>
              </a-form-model-item> -->
              <a-row>
                <a-col :span="8">
                  <a-form-model-item label="贷款方式：">
                    <a-select
                      v-model="form.loanType"
                      placeholder="请选择"
                      class="mr-32"
                      style="width: 300px"
                    >
                      <a-select-option :value="''">请选择</a-select-option>
                      <a-select-option
                        v-for="(item, index) in loanTypes"
                        :key="item.dictValue"
                        :value="item.dictValue"
                        >{{ item.dictLabel }}</a-select-option
                      >
                    </a-select>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="产品类型：">
                    <a-select
                      v-model="form.type"
                      placeholder="请选择"
                      class="mr-32"
                      style="width: 300px"
                    >
                      <a-select-option :value="''">请选择</a-select-option>
                      <a-select-option
                        v-for="(item, index) in prodcutTypes"
                        :key="item.dictValue"
                        :value="item.dictValue"
                        >{{ item.dictLabel }}</a-select-option
                      >
                    </a-select>
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-form-model-item label="有效期限">
                  <a-range-picker
                    format="YYYY-MM-DD"
                    @change="timeSelect"
                    style="width: 300px"
                  />
                </a-form-model-item>
              </a-row>
              <a-form-model-item label="融资额度">
                <a-input
                  class="no-number"
                  type="number"
                  v-model="form.financingAmountStart"
                  style="width: 180px"
                  suffix="万元"
                  :min="0"
                  :max="9999"
                />
                <span style="margin: 0 8px">至</span>
                <a-input
                  class="no-number"
                  type="number"
                  v-model="form.financingAmountEnd"
                  style="width: 180px"
                  suffix="万元"
                  :min="0"
                  :max="9999"
                />
              </a-form-model-item>
            </a-form-model>
          </div>
        </div>
      </div>

      <div class="main-searchResult clearfix">
        <div class="f-left search-left">
          <span v-if="newskeyword != ''">
            搜索："
            <span class="search-text1">{{ newskeyword }}</span>
            "
          </span>
          共
          <span class="search-text2">{{ total }} </span>条数据
        </div>
        <div class="f-right search-right clearfix">
          <a-button @click="SwitchisOrderDesc">
            <div class="f-left search-right-icon">
              <div>
                <a-icon
                  :class="!form.isOrderDesc ? '' : 'down'"
                  type="caret-up"
                />
              </div>
              <div>
                <a-icon
                  :class="form.isOrderDesc ? '' : 'down'"
                  type="caret-down"
                />
              </div>
            </div>
            <div class="f-left remainingTime">发布时间</div>
          </a-button>
        </div>
      </div>

      <!--列表模块-->
      <div class="list-box">
        <ul>
          <li
            class="pb-16 pt-8 pr-8 mt-16"
            v-for="(item, index) in TableData"
            :key="index"
          >
            <div class="row-box" @click="toDetail(item.id)">
              <div class="ent_logo">
                <img v-if="item.cover" :src="item.cover" alt="" />
                <img
                  v-else
                  class="defult_img"
                  src="@/assets/images/defult_img.png"
                  alt=""
                />
              </div>
              <div class="expire pl-20"></div>
              <div class="content-title">
                <div class="content-title-text clearfix">
                  <div class="f-left"></div>
                  <div class="f-left row-title">
                    {{ item.name ? item.name : "无" }}
                    <!-- <span class="tags">母婴</span> -->
                    <!-- <span class="tags">制造</span> -->
                  </div>
                </div>
              </div>
              <div class="row-mainBox">
                <ul>
                  <li>
                    <span>
                      <a-icon type="tag" theme="filled" style="color: green" />
                    </span>
                    <span class=""> 发布机构：{{ item.pubInstitution }} </span>
                  </li>
                  <li class="flex mt-8">
                    <div class="item">
                      <span class="disc">
                        <a-icon
                          type="environment"
                          theme="filled"
                          style="color: blue"
                        />
                      </span>
                      产品类型：
                      <span>
                        {{ getProdcutTypeDictLabel(item.type, prodcutTypes) }}
                      </span>
                    </div>
                    <div class="item">
                      <span class="disc">
                        <a-icon
                          type="file-text"
                          theme="filled"
                          style="color: orange"
                        />
                      </span>
                      融资额度：
                      <span> {{ item.financingAmount }}万 </span>
                    </div>
                    <div class="item">
                      <span class="disc">
                        <a-icon
                          type="file-text"
                          theme="filled"
                          style="color: orange"
                        />
                      </span>
                      参考利率：
                      <span> {{ item.rate }}% </span>
                    </div>
                  </li>
                  <li class="flex mt-8">
                    <div class="item">
                      <span class="disc">
                        <a-icon
                          type="money-collect"
                          theme="filled"
                          style="color: red"
                        />
                      </span>
                      贷款方式：
                      <span>
                        {{ getProdcutTypeDictLabel(item.loanType, loanTypes) }}
                      </span>
                    </div>
                    <div class="item">
                      <span class="disc">
                        <a-icon
                          type="carry-out"
                          theme="filled"
                          style="color: red"
                        />
                      </span>
                      融资期限：
                      <span>2024/9/30</span>
                    </div>
                    <div class="item">
                      <span class="disc">
                        <a-icon
                          type="file-text"
                          theme="filled"
                          style="color: orange"
                        />
                      </span>
                      申请数量：
                      <span>：{{ Number(item.applyNum) }}</span>
                    </div>
                  </li>
                </ul>
              </div>
              <div class="clearfix row-footer">
                <div class="f-left row-footer-text">
                  <p>{{ item.desc }}</p>
                </div>
              </div>
            </div>
          </li>
        </ul>
      </div>
      <NoData v-if="TableData.length <= 0" :Keywords="newskeyword"></NoData>
      <div v-if="TableData.length > 0" class="mt-40 tc mb-100">
        <a-pagination
          :show-total="(total) => `共有 ${total} 条数据`"
          show-quick-jumper
          :current="form.current"
          @showSizeChange="showSizeChanger"
          show-size-changer
          :defaultPageSize="10"
          :pageSizeOptions="['10', '20', '30', '40']"
          :total="total"
          @change="onChange"
        />
      </div>
    </div>
  </div>
</template>
<script>
import NoData from "@/components/Nodata";

import { getentMerchantsList } from "@/apis/EntMerchants";
import { getClientCrelist } from "@/apis/cre/crePord";
import { getDicts } from "@/apis/system";
import { listBanner } from "@/apis/cre/creBanner";
import Suggest from "./suggest.vue";
import { getToken } from "@/utils/auth"; // get token from cookie

export default {
  components: {
    Suggest,
    NoData,
  },
  data() {
    return {
      show: false,
      selectType: [
        { name: "电子", key: 1 },
        { name: "织纺", key: 2 },
        { name: "化工", key: 3 },
        { name: "建材", key: 4 },
        { name: "机械", key: 5 },
        { name: "轻工", key: 6 },
        { name: "食品", key: 7 },
        { name: "冶金", key: 8 },
        { name: "制药", key: 9 },
        { name: "通用服务", key: 10 },
        { name: "抗议物资", key: 11 },
      ],
      form: {
        // type: 1, //1招商，2招标
        size: 10,
        keyword: "",
        isOrderDesc: true,
        current: 1,
        auditStatus: 2,
        publishDateStart: "",
        publishDateEnd: "",
        financingAmountStart: null,
        financingAmountEnd: null,
        loanType: "",
        type: "",
      },
      newskeyword: "",
      publishDateStart: "",
      publishDateEnd: "",
      total: 0,
      TableData: [],
      prodcutTypes: [],
      loanTypes: [],
      bannerList: [],
    };
  },
  mounted() {
    this.getLoanTypes();
    this.getProdcutTypes();
    this.getentMerchantsList();
    this.getBannerList();
  },

  methods: {
    getToken,
    async getBannerList() {
      this.bannerList = await listBanner();
      // console.log('getBannerList', res);
      // this.bannerList = res.rows
    },

    /** 获取贷款类型字典 */
    async getLoanTypes() {
      const { data } = await getDicts("cre_loan_type");
      this.loanTypes = data;
    },
    /** 获取信贷产品类型字典 */
    async getProdcutTypes() {
      const { data } = await getDicts("cre_product_type");
      this.prodcutTypes = data;
      console.log("this.prodcutTypes", this.prodcutTypes);
    },
    getProdcutTypeDictLabel(val, array) {
      const obj = array.find((item) => item.dictValue == val);
      if (obj) {
        return obj.dictLabel;
      } else {
        return "";
      }
    },

    timeSelect(date, dateStr) {
      this.form.publishDateStart = dateStr[0];
      this.form.publishDateEnd = dateStr[1];
    },
    SearchData() {
      if (this.form.keyword != "") {
        this.newskeyword = this.form.keyword;
      } else {
        this.newskeyword = "";
      }
      this.publishDateStart = this.form.publishDateStart;
      this.publishDateEnd = this.form.publishDateEnd;

      console.log(Number(this.form.financingAmountStart) == NaN);

      if (
        typeof this.form.financingAmountStart != null &&
        Number(this.form.financingAmountStart) == NaN
      ) {
      }
      if (
        typeof this.form.financingAmountEnd &&
        typeof this.form.financingAmountStart != "number"
      ) {
      }
      this.onChange(1);
    },
    //排序
    SwitchisOrderDesc() {
      this.form.isOrderDesc = !this.form.isOrderDesc;
      this.getentMerchantsList();
    },
    toDetail(id) {
      if (!getToken()) {
        this.$message.warning("您需要登录再进行该操作");
        return;
      }
      this.$router.push("/AttractInvestmentDetails?merchantsid=" + id);
    },
    // 当前页
    onChange(page, pageSize) {
      this.form.current = page;
      this.getentMerchantsList();
    },
    //每页显示条数
    showSizeChanger(current, size) {
      this.form.size = size;
      this.form.current = current;
      this.getentMerchantsList();
    },
    toHomePage() {
      this.$router.push("/homePage");
    },
    resetForm() {
      this.$refs.ruleForm.resetFields();
    },
    // 获取招商合作列表
    getentMerchantsList() {
      let _param = {
        type: this.form.type,
        pageSize: this.form.size,
        pageNum: this.form.current,
        name: this.newskeyword,
        isOrderDesc: this.form.isOrderDesc ? "desc" : "asc",
        approvalStatus: 1,
        isGround: 1,
        closeDateStart: this.form.publishDateStart,
        closeDateEnd: this.form.publishDateEnd,
        isNow: true,
        financingAmountStart: this.form.financingAmountStart,
        financingAmountEnd: this.form.financingAmountEnd,
        loanType: this.form.loanType,
        type: this.form.type,
      };
      //getClientCrelist
      getClientCrelist(_param)
        .then((res) => {
          console.log("招商合作列表");
          console.log(res);
          if (res.code == 200) {
            this.TableData = res.rows;
            this.total = res.total;
          }
        })
        .catch((error) => {});
    },
  },
};
</script>
<style lang="less" scoped>
.AttractInvestment {
  .banner {
    background: url("../../../assets/images/attract.png") no-repeat center;
    height: 200px;

    h1 {
      height: 60px;
      line-height: 60px;
      color: rgb(7, 41, 71);
      font-size: @font36;
      font-weight: lighter;
    }

    span {
      font-size: @font36;
      color: rgba(7, 41, 71, 58%);
    }
  }

  .main-title {
    img {
      width: 40px;
      height: 40px;
      margin-right: 16px;
      vertical-align: middle;
      margin-top: -10px;
    }

    span {
      font-family: Microsoft YaHei;
      font-size: @font26;
      line-height: @font26;
      font-weight: 700;
      color: @text-color-303;
    }
  }

  .main-search {
    margin-top: 24px;
    margin-bottom: 24px;

    ::v-deep .ant-col-2 {
      width: auto !important;
    }

    &:nth-child(1) {
      font-family: Microsoft YaHei;
      font-size: @font14;
      font-weight: normal;
      line-height: 19px;
      color: @text-color-606;
      margin-right: 8px;
    }

    .ant-input {
      width: 500px;
      height: 40px;
    }

    .ant-btn1 {
      margin-left: 12px;
      margin-right: 40px;
      width: 100px;
      height: 40px;
      background-color: #2a51bc;
      box-shadow: 0px 10px 20px 0px rgba(7, 41, 71, 0.16);
      border-radius: 4px;
      color: #fff;
    }

    .show-btn {
      cursor: pointer;

      &:hover {
        color: #188af1;
      }
    }

    &:nth-child(4) {
      font-family: Microsoft YaHei;
      font-size: @font16;
      font-weight: normal;
      line-height: 21px;
      color: @text-color-606;
    }
  }

  .main-searchResult {
    height: 70px;
    line-height: 70px;
    background-color: #fff;
    box-shadow: 0px 3px 10px 0px rgba(24, 138, 241, 0.16);
    border-radius: 4px;
    margin-bottom: 32px;

    .search-left {
      margin-left: 26px;
      font-size: @font16;

      .search-text1 {
        color: #2a51bc;
      }

      .search-text2 {
        color: #e9284f;
        font-weight: 700;
      }
    }

    .search-right {
      margin-right: 24px;

      .ant-btn {
        margin-left: 16px;
        width: 120px;
        height: 40px;
        line-height: 1;
        border: solid 1px #188af1;
        color: #188af1;
        font-size: @font16;

        &:hover {
          background-color: #188af1;
          color: #fff;
        }
      }

      .down {
        opacity: 0.5;
      }

      .remainingTime {
        padding-left: 5px;
        line-height: 32px;
      }

      .search-right-icon {
        div {
          width: 14px;
          height: 9px;
        }

        padding-top: 3px;
      }
    }
  }

  .list-box {
    ul li {
      .row-box {
        padding: 28px 32px;
        border: solid 1px #e4e7ed;
        position: relative;
        background-color: #ffffff;
        margin-bottom: 24px;
        cursor: pointer;

        .ent_logo {
          width: 213px;
          height: 139px;
          display: flex;
          overflow: hidden;
          justify-content: center;
          align-items: center;
          background-color: #ffffff;
          box-shadow: 6px 6px 20px 0px rgba(24, 138, 241, 0.16);
          border-radius: 4px;
          position: absolute;
          right: 24px;
          top: -30px;

          img {
            width: auto;
            max-height: 120px;
            object-fit: cover;
          }
        }

        &:hover {
          .row-title {
            color: #2a51bc;
          }
        }

        .expire {
          text-align: center;
          position: absolute;
          top: -1px;
          left: 0;
          font-size: @font16;
          color: #fff;
          border-bottom-right-radius: 80%;
          width: 35px;
          height: 42px;
          background-image: url("../Enterprise/image/left_bg.png");
          background-size: 100% 100%;
          background-repeat: no-repeat;
        }

        .content-title {
          font-size: 26px;

          .content-title-text {
            .tags {
              display: inline-block;
              height: 24px;
              line-height: 24px;
              background-color: #ffffff;
              border: solid 1px #0da9b0;
              font-size: 14px;
              padding: 0px 10px;
              border-radius: 10px;
              margin-right: 10px;

              &:nth-child(1) {
                border: solid 1px #0da9b0;
                color: #0da9b0;
              }

              &:nth-child(2) {
                border: solid 1px #188af1;
                color: #188af1;
              }
            }
          }
        }

        .row-mainBox {
          padding: 6px 0;

          .item {
            width: 180px;
            margin-right: 10px;
          }

          .address_icon {
            color: #2a51bc;
            margin-right: 4px;
          }

          .momey_icon {
            color: #e9284f;
            margin-right: 4px;
          }

          .data_cion {
            color: #e9284f;
            margin-right: 4px;
          }

          ul {
            li {
              font-size: @font14;
              font-family: Microsoft YaHei;
              line-height: 24px;
              font-weight: normal;
              color: @text-color-909;
            }
          }
        }

        .row-footer {
          margin: 17px 0 0;

          .row-footer-text {
            width: 100%;
            font-family: Microsoft YaHei;
            background-color: #f5f7fa;
            border-radius: 4px;
            padding: 24px;
            font-size: @font16;
            font-weight: normal;
            color: #909399;

            p {
              -webkit-line-clamp: 3; // 用来限制在一个块元素显示的文本的行数
              display: -webkit-box; // 将对象作为弹性伸缩盒模型显示
              -webkit-box-orient: vertical; //设置或检查伸缩盒对象的子元素的排列方式
              text-overflow: ellipsis; // 在多行文本的情况下，用...隐藏超出范围的文本
              word-break: break-all;
              overflow: hidden;
            }
          }

          .right-icon {
            width: 18px;
            height: 18px;
            line-height: 24px;
            color: #909399;
          }
        }
      }
    }
  }
}

.banner-box {
  position: relative;
  // width: 100%;
  height: 460px;

  .arrow {
    position: absolute;
    top: 50%;
    z-index: 999;
    color: #fff;
    font-size: 24px;
    transform: translateY(-50%);
    opacity: 0.5;
    cursor: pointer;
  }

  .prev {
    left: 20px;
  }

  .next {
    right: 20px;
  }
}

.banner-item {
  position: relative;
  width: 100%;
  height: 460px;
  cursor: pointer;

  .banner-txt {
    position: absolute;
    right: 10px;
    bottom: 10px;
    display: inline;
  }
}
</style>

<style scoped>
/* For demo */
.ant-carousel >>> .slick-slide {
  text-align: center;
  height: 460px;
  /* line-height: 160px; */
  background: #364d79;
  overflow: hidden;
}

.ant-carousel >>> .custom-slick-arrow {
  width: 25px;
  height: 25px;
  font-size: 25px;
  color: #fff;
  background-color: rgba(31, 45, 61, 0.11);
  opacity: 0.3;
}

.ant-carousel >>> .custom-slick-arrow:before {
  display: none;
}

.ant-carousel >>> .custom-slick-arrow:hover {
  opacity: 0.5;
}

.ant-carousel >>> .slick-slide h3 {
  color: #fff;
}
</style>
